package no.hig.imt4721.presentation;

import java.util.List;

import javax.swing.JFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class Graph extends JFrame
{
	private static final long serialVersionUID = 6859382038761992009L;
	
	private static String X_AXIS_LABEL = "Session";
	private static String Y_AXIS_LABEL = "Average SD";
	
	public void draw(List<Double> y, String graphName)
	{
		XYSeriesCollection dataset = new XYSeriesCollection();
		
		XYSeries series = new XYSeries(graphName);
			
		for(int i = 0; i < y.size(); i++)
			series.add((i+1), y.get(i));
		
		dataset.addSeries(series);
        
        JFreeChart chart = ChartFactory.createXYLineChart(graphName, X_AXIS_LABEL, Y_AXIS_LABEL, dataset, PlotOrientation.VERTICAL, true, false, false);
        
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));
        setContentPane(chartPanel);
        
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.getDomainAxis().setLowerBound(1);
        plot.getDomainAxis().setUpperBound(8);
        plot.getRangeAxis().setLowerBound(0.055);
        plot.getRangeAxis().setUpperBound(0.105);
        
        ((NumberAxis)plot.getDomainAxis()).setTickUnit(new NumberTickUnit(1));
        ((NumberAxis)plot.getRangeAxis()).setTickUnit(new NumberTickUnit(0.01));

        
        
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle(graphName);
        
		pack();
		setVisible(true);
	}
}
